//
//  Quiz.1.c
//  electronic-calculator
//
//  Created by YEONGEON on 11/2/11.
//  Copyright (c) 2011 mypola.net. All rights reserved.
//

#include <stdio.h>



/**
 * Right!!
 *
 * Quiz.1 - 3 Sulution Function.
 *
 * @return int
 */
int QZ1_main_3()
{
	int n = 22;
	int i =900;
	int j =1000;
	int length = 0;
	int maxlength = 0;
	int max_n = 0;
	
	for( int m = i; m<=j ; m++)
	{
		n=m;
		length = 0;
		while (n!=1) {
			// ODD
			if((n&0x1) ){
				n = (n<<1) + n +1;
				// 3n +1
			}
			// Even
			else{
				n = (n>>1);
				// n/2
			}
			
			length++;
		}
		length++;
		
		if( maxlength < length )
		{
			maxlength = length;
			max_n = m;
		}
		
		//	printf("++++ %d %d %d\n", i, j, maxlength);
		
	}
	printf("++++ %d %d %d : %d\n", i, j, maxlength, max_n);
	return 0;
	
}


/**
 * Right!!
 *
 * Quiz.1 - 2 Sulution Function.
 *
 * @return int
 */
int QZ1_main_2()
{
	int n = 22;
	int i =900;
	int j =1000;
	int length = 0;
	int maxlength = 0;
	int max_n = 0;
	
	for( int m = i; m<=j ; m++)
	{
		n=m;
		length = 0;
		while (n!=1) {
			//length++;
			
			// ODD
			if(n%2==0){
				n = n/2;
			}
			// Even
			else{
				n = n*3 +1;
			}
			
			length++;
		}
		length++;
		
		if( maxlength < length )
		{
			maxlength = length;
			max_n = m;
		}
		
		//	printf("++++ %d %d %d\n", i, j, maxlength);
		
	}
	printf("++++ %d %d %d : %d\n", i, j, maxlength, max_n);
	return 0;
	
}


/**
 * Wrong!!
 *
 * Quiz.1 - 1 Sulution Function.
 *
 * @return int
 */
int QZ1_main_1()
{
	int n = 22;
	int i =1;
	int j =10;
	int length = 0;
	
	
	while (n>0) {
		//length++;
		
		// ODD
		if(n%2==0){
			n = n/2;
		}
		// Even
		else{
			if (n==1) {
				break;
			}
			n = n*3 +1;
		}
		
		if (n>=i && n<=j) {
			
			
			length++;
			printf("++++ %d : %d %d %d\n", n, i, j, length);
			
			
		}
		
		
	}
	printf("++++ %d %d %d\n", i, j, length);
	
	return 0;
}



/**
 * Quiz.1 Main Function for the Run.
 *
 * @return int
 */
int QZ1_main()
{
	//	return QZ1_main_1();
	//return QZ1_main_2();
	return QZ1_main_3();
}

